package com.h2.ref.server.user.model;

import java.util.ArrayList;
import java.util.List;

public class User {
   
   private Integer _id;

   private String _name;
   
   private String _password;
   
   private Boolean _isActive;
   
   private UserDetails _userDetails;
   
   private List<String> _roles;
   
   ////
   ////
   
   public User() {
      //nothing to do
   }
   
   public User(Integer id) {
      setId(id);
   }
   
   public User(String name, String password) {
      setName(name);
      setPassword(password);
      setActive(Boolean.TRUE);
   }
   
   public User copy() {
      User copy = new User();
      copy.setId(getId());
      copy.setName(getName());
      copy.setPassword(getPassword());
      copy.setActive(isActive());
      if (getUserDetails() == null) {
         copy.setUserDetails(new UserDetails());
      }
      else {
         copy.setUserDetails(getUserDetails().copy());
      }
      if (getRoles() != null) {
         copy.setRoles(new ArrayList<String>(getRoles()));
      }
      
      return copy;
   }

   /**
    * @return the id
    */
   public Integer getId() {
      return _id;
   }

   /**
    * @param id the id to set
    */
   public void setId(Integer id) {
      _id = id;
   }

   /**
    * @return the name
    */
   public String getName() {
      return _name;
   }

   /**
    * @param name the name to set
    */
   public void setName(String name) {
      _name = name;
   }

   /**
    * @return the password
    */
   public String getPassword() {
      return _password;
   }

   /**
    * @param password the password to set
    */
   public void setPassword(String password) {
      _password = password;
   }

   /**
    * @return the roles
    */
   public List<String> getRoles() {
      return _roles;
   }

   /**
    * @param roles the roles to set
    */
   public void setRoles(List<String> roles) {
      _roles = roles;
   }

   /**
    * @return the isActive
    */
   public Boolean isActive() {
      return _isActive;
   }

   /**
    * @param isActive the isActive to set
    */
   public void setActive(Boolean isActive) {
      _isActive = isActive;
   }

   /**
    * @return the userDetails
    */
   public UserDetails getUserDetails() {
      return _userDetails;
   }

   /**
    * @param userDetails the userDetails to set
    */
   public void setUserDetails(UserDetails userDetails) {
      _userDetails = userDetails;
   }

   /* (non-Javadoc)
    * @see java.lang.Object#hashCode()
    */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((_id == null) ? 0 : _id.hashCode());
      return result;
   }

   /* (non-Javadoc)
    * @see java.lang.Object#equals(java.lang.Object)
    */
   @Override
   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      }
      if (obj == null) {
         return false;
      }
      if (!(obj instanceof User)) {
         return false;
      }
      User other = (User) obj;
      if (_id == null) {
         if (other._id != null) {
            return false;
         }
      } else if (!_id.equals(other._id)) {
         return false;
      }
      return true;
   }
}
